package com.poobo.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.poobo.condiction.EqGameInfoCondiction;
import com.poobo.dao.IEqGamesInfoDao;
import com.poobo.dao.IEquipmentDao;
import com.poobo.dao.IResourcesDao;
import com.poobo.entity.TbConfigList;
import com.poobo.entity.TbEqGamesInfo;
import com.poobo.entity.TbEquipment;
import com.poobo.entity.TbEquipmentConfiglist;
import com.poobo.entity.TbResources;
import com.poobo.service.IEqGamesInfoService;
import com.poobo.util.pager.Page;

@Service
@Transactional
public class EqGamesInfoServiceImpl implements IEqGamesInfoService{
	@Autowired
	private IEqGamesInfoDao eqGamesInfoDao;
	@Autowired
	private IEquipmentDao equipmentDao;
	@Autowired
	private IResourcesDao resourcesDao;

	@Override
	public List<TbEqGamesInfo> queryAll() {
		return eqGamesInfoDao.queryAll();
	}

	@Override
	public TbEqGamesInfo queryEqGamesInfoById(Integer id) {
		return eqGamesInfoDao.queryEqGamesInfoById(id);
	}

	@Override
	public Page queryEqGamesInfoPage2(TbEqGamesInfo eqGamesInfo, Page page) {
		return eqGamesInfoDao.queryEqGamesInfoPage2(eqGamesInfo, page);
	}

	@Override
	public void deleteEqGamesInfoById(Integer id) {
		eqGamesInfoDao.deleteEqGamesInfoById(id);
	}

	@Override
	public void saveEqGamesInfo(TbEqGamesInfo eqGamesInfo) {
		eqGamesInfoDao.saveEqGamesInfo(eqGamesInfo);
	}

	@Override
	public Page queryEqGamesInfoPage(EqGameInfoCondiction eqGameInfoCondiction,
			Page page) {
		return eqGamesInfoDao.queryEqGamesInfoPage(eqGameInfoCondiction, page);
	}

	@Override
	public void updateIsDefault(Integer eqid) {
		eqGamesInfoDao.updateIsDefault(eqid);
	}

	@Override
	public void deleteEqGamesInfoByEquipmentId(Integer eqid) {
		eqGamesInfoDao.deleteEqGamesInfoByEquipmentId(eqid);
	}

	@Override
	public void deleteEqGamesInfoByResourcesId(Integer reid) {
		eqGamesInfoDao.deleteEqGamesInfoByResourcesId(reid);
	}

	@Override
	public TbEqGamesInfo queryEqGamesInfoByEquipmentId(Integer id) {
		return eqGamesInfoDao.queryEqGamesInfoByEquipmentId(id);
	}

	@Override
	public List<Map<String, String>> findDefaultGame() {
		List<TbEqGamesInfo> eqGamesInfos = eqGamesInfoDao.findDefaultGame();
		Map<String, String> map = new HashMap<String, String>(); 
		List<Map<String, String>> maps = new ArrayList<Map<String,String>>();
		TbEqGamesInfo eqGamesInfo = null;
		TbEquipment equipment = null;
		TbResources resources = null;
		if( eqGamesInfos != null && eqGamesInfos.size() > 0 ){
			for( int i=0; i<eqGamesInfos.size(); i++ ){
				eqGamesInfo = eqGamesInfos.get(i);
				equipment = equipmentDao.queryEquipmentById(eqGamesInfo.getEqid());
				resources = resourcesDao.queryResourcesById(eqGamesInfo.getReid());
				if( equipment !=null && resources != null ){					
					map.put("number", equipment.getNumber());
					map.put("resourcesName", resources.getName());
					map.put("resourcesURL", resources.getPath());
					maps.add(map);
				}
			}
		}
		return maps;
	}

}
